#encoding=UTF-8
'''python操作mysql'''
import pymysql

# 测试
def testConn():

    #创建数据库连接
    db = pymysql.connect(host="hadoop102",user="root",password="123456",
                database="test")
    # 创建cursor对象
    cursor = db.cursor()
    # 执行sql语句
    cursor.execute("select version()")
    # 获取结果
    data = cursor.fetchone()
    print("Database version : %s " % data)
    # 关闭连接
# 建表语句
def createTable():
    db = pymysql.connect(host="hadoop102",user="root",password="123456",database="test")
    cursor = db.cursor()
    # 执行建表语句
    cursor.execute("create table user (id int,name varchar(255))charset='UTF8'")
    db.close()
# 向表里插入数据
def insertData():
    db = pymysql.connect(host="hadoop102", user="root", password="123456", database="test")
    cursor = db.cursor()
    id = 4
    name = "zhaoliu"
    try:
        # 执行建表语句 注意字符串自己加双引号
        cursor.execute(f'''
            insert into user values ({id},"{name}")
            ''' )
        db.commit()
    except:
        db.rollback()
    db.close()

def selectData():
    db = pymysql.connect(host="localhost", user="root", password="123456", database="test")
    cursor = db.cursor()
    # 查询数据
    cursor.execute("select * from user")
    # 获取数据
    data = cursor.fetchall()
    for row in data:
        id = row[0]
        name = row[1]
        print(f"{id}:{name}")
    db.close()

# if __name__ == '__main__':
    # testConn()
    # createTable() # 建表
    # insertData() #插入数据
    # selectData() # 查询数据



import pandas as pd
from sklearn.model_selection import train_test_split

# 1、计算样本特征的相关性
df = pd.read_csv('直播数据集.csv')
print(df.head(10))
print(df.info())

# 2、将数据拆分成训练集和测试集。
X = df.drop(['点赞数','主播姓名','直播标题','时间'],axis=1)
y = df['点赞数']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.7, random_state=42)


# 3、选择两种合适的算法，对主播的受欢迎程度进行数据建模




# 3、使用最佳模型预测样本数据，并将结果带入到MySQL




